uniform float	specularExponent;

void main() {
	// std transform
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	
	// get vertex normal
	vec3	N = normalize(gl_NormalMatrix * gl_Normal);
	
	// world coord of vertex
	vec4	V = gl_ModelViewMatrix * gl_Vertex;
	
	// vector from world vertex to light location
	vec3	L = normalize(gl_LightSource[0].position.xyz - V.xyz);
	
	// work out diffuse intensity
	vec4	diffuseIntensity = vec4(max(0.0, dot(N, L)));
	
	// get the specular factor
	// get half vector between the view vector (unit z) and the light vector L
	vec3	H = normalize(L + vec3(0, 0, 1));
	
	// get the angle between N and H
	float	NdotH = max(0.0, dot(N, H));
	vec4	specularIntensity = vec4(0.0);
	
	if(NdotH > 0.0) {
		specularIntensity = vec4(pow(NdotH, specularExponent));
	}
	
	// multiply the colour by the light intensity 
	gl_FrontColor = gl_Color * (diffuseIntensity + specularIntensity);	
}
